<template>
	<view>
		<image class="bgImage" src="/static/image/guide/homeBg.png" mode="widthFix"></image>
		<view class="navBox">
			<image class="backBtn" @click="goBack" src="http://cdn.yic3.cn/lawyer/mp-xhs/mine/backIcon.png"
				mode="widthFix"></image>
			<p>合同审查记录</p>
		</view>
		<view class="" style="width: 100%;height: 188rpx;"></view>
		<view class="tabsBox">
			<p @click="changeTabs(item.module,index)" :class="item.module == module && 'active'"
				v-for="(item,index) in tabsList" :key="index">{{item.name}}</p>
		</view>
		<scroll-view refresher-enabled refresher-default-style="white" @refresherrefresh="refresherrefresh"
			:refresher-triggered="isTriggered" refresher-background="transparent" @scrolltolower="listLower"
			class="listBox" :scroll-y="true">
			<delSlideLeft :item="item" v-for="(item,index) in datalist" :key="item.id"
				:data_transit="{index:index,item:item}" @delItem="openDel">
				<view class="listItem" @click.stop="item.status == 2 && goDetail(item)">
					<view class="">
						<image src="http://cdn.yic3.cn/lawyer/mp-xhs/mine/icon17.png" mode=""></image>
						<text>{{item.fileName}}</text>
					</view>
					<view class="" v-if="item.status == 2"
						>
						<text>查看</text>
						<image src="http://cdn.yic3.cn/lawyer/mp-xhs/mine/icon16.png" mode=""></image>
					</view>
					<view class="" v-if="item.status == 1">
						<u-loading-icon mode="circle" size="18" color="#4EBC7B"></u-loading-icon>
					</view>
					<view class="" v-if="item.status == 3">
						失败
					</view>
				</view>
			</delSlideLeft>

			<u-loadmore v-if="!isTriggered && datalist.length" @loadmore="loadmore"
				style="display: flex;justify-content: center;width: 100%;" :status="status" loading-text="加载中..."
				nomore-text="没有更多数据" />
			<view class="emptyBox" v-if="!loading && !datalist.length">
				<!-- <image src="https://cdn.yic3.cn/lawyer/mp-xhs/mine/data.png" mode="widthFix"></image> -->
				<text>暂无相关数据</text>
			</view>
		</scroll-view>
		<u-popup :show="popshow" bgColor="transparent" mode="center">
			<view class="popBox">
				<view class="title">
					删除内容
				</view>
				<view class="content">
					确定要删除这条记录吗？
				</view>
				<view class="btn">
					<text @click="delItem">删除</text>
					<text @click="popshow = false">取消</text>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import delSlideLeft from '@/components/ay-operate/del_slideLeft.vue'
	export default {
		components: {
			delSlideLeft,
		},
		data() {
			return {
				popshow: false,
				datalist: [],
				page: 1,
				status: 'loading',
				loading: false,
				isTriggered: false,
				refresher: true,
				module: 2,
				delId: '',
				delIndex: '',
				tabsList: [{
						name: '已审查',
						module: 2
					},
					{
						name: '审查中',
						module: 1
					}
				]
			};
		},
		onLoad(e) {
			this.module = e.module || 2
			this.getContractView()
		},
		methods: {
			// 触底加载
			listLower() {
				if (this.loading || this.status == 'nomore') return
				this.loading = true
				this.page++
				this.getContractView()
			},
			// 切换tabs
			changeTabs(module, index) {
				this.module = module
				this.page = 1
				this.datalist = []
				this.getContractView()
			},
			goDetail(item){
				// #ifdef APP
				this.goItemDetail('/packageA/pages/fileReview/fileReview',item)
				// #endif
				// #ifdef MP
				this.goItemDetail('/packageA/pages/reviewRecord/reviewDetail',item)
				// #endif
			},
			openDel(e) {
				this.delId = e.item.id
				this.delIndex = e.item.index
				this.popshow = true
			},
			delItem(e) {
				uni.showLoading()
				this.$api.delReviewRecord({
					contractId: this.delId
				}).then(res => {
					this.popshow = false
					uni.hideLoading()
					console.log(res)
					if (res.data.code == 0) {
						this.datalist.splice(this.delIndex, 1)
						uni.showToast({
							title: '删除成功'
						})
					}
				})
			},
			loadmore() {
				this.page++
				this.getContractView()
			},

			// 下拉刷新
			refresherrefresh(e) {
				this.isTriggered = true
				this.page = 1
				this.datalist = []
				this.getContractView()
			},
			// 请求数据
			getContractView() {
				this.loading = true
				this.$api.getContractView({
					page: this.page,
					size: 10,
					status: this.module
				}).then(res => {
					console.log(2)
					this.loading = false
					this.isTriggered = false
					if (res.data.code == 0) {
						this.datalist = [...this.datalist, ...res.data.data.items]
						if (res.data.data.items.length < 10) {
							this.status = 'nomore'
						}
					}

					console.log(res)
				})
			}
		},
	}
</script>

<style lang="scss">
	page {
		background-color: #15161C;
	}

	@import 'reviewRecord.scss'
</style>